package com.lw.question04;

/**
 * @author LW
 * @2020/9/15 14:51
 */
public class 循环输出对象的值3 {
    public static void main(String[] args) {

        int num=0;
        Student s1 = new Student(1,"张1",3);
        Student s2 = new Student(2,"张2",5);
        Student s3 = new Student(3,"张3",10);
        Student s4 = new Student(4,"张4",14);
        Student s5 = new Student(5,"张5",25);
        Student[] s ={s1,s2,s3,s4,s5};
        for (int i = 0; i < s.length; i++) {
            System.out.println("学生id=="+s[i].getId());
            System.out.println("学生姓名=="+s[i].getName());
            System.out.println("学生年龄=="+s[i].getAge());
            System.out.println("======================================");
            s[i].age=s[i].getAge()+1;
//            System.out.println("学生年龄=="+s[i].getAge());
            if (s[i].getAge()>20){
                num++;
            }
        }

        System.out.println("学生年龄大于20岁的有"+num+"人");


    }

    public static class Student{
        private int id;
        private String name;
        private int age;

        //创建对象时可以直接赋值
        public Student(int id, String name, int age) {
            this.id = id;
            this.name = name;
            this.age = age;
        }

        public int getId() {
            return id;
        }

        public void setId(int id) {
            this.id = id;
        }

        public String getName() {
            return name;
        }

        public void setName(String name) {
            this.name = name;
        }

        public int getAge() {
            return age;
        }

        public void setAge(int age) {
            this.age = age;
        }
    }
}


